<template>
    <div class="components-container">
        <!-- 编辑 -->
        <sweet-modal v-if="hidden === 1" ref="dialog" class="dialog" :sweetModalMaxWidth="930">
            <h3>{{title}} </h3>
            <fieldset class="layui-elem-field layui-field-title">
            <legend>死者信息</legend>
            <div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">业务编号</label>
                    <div class="layui-input-inline">
                        <el-input v-model="crhData.REGNO" placeholder="请输入业务编号" @keyup.enter.native="getRegInfo">
                        <el-button slot="append" icon="el-icon-search" @click="getRegInfo"></el-button>
                        </el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">逝者姓名</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGNAME" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGSEXDESC" readonly></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">年龄</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGAGE" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">接尸日期</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGDATE" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">接尸地点</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGADDRESS" readonly></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">详细地址</label>
                    <div class="layui-input-inline" style="width:480px">
                        <el-input v-model="regList.REGDETAILADDRESS" readonly></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">联系人</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGHANDLERNAME" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">联系电话</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGHANDLERLINK" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGREMARK" readonly></el-input>
                    </div>
                </div>
            </div>
            </div>
            </fieldset>
            <fieldset class="layui-elem-field layui-field-title">
            <legend>火化炉使用信息</legend>
            <div class="layui-form-item" v-if="this.isshow">
                <div class="layui-inline">
                    <label class="layui-form-label">起始油量</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.CRHBEGOIL"></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">结束油量</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.CRHENDOIL"></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">炉子编号</label>
                    <div class="layui-input-inline">
                        <el-select v-model="crhData.CRENO" placeholder="请选择火化炉编号" style="width:100%">
                            <el-option v-for="item in creNames" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </div>
               <div class="layui-inline" v-if="showluxing">
                        <label class="layui-form-label">火化炉类型</label>
                        <div class="layui-input-inline">
                             <el-select v-model="crhData.REGCRETYPE" filterable>
                                    <el-option v-for="item in hhldata" :key="item.Value" :label="item.Text" :value="item.Value">
                                    </el-option>
                                </el-select>
                         </div>
                 </div>
                <div class="layui-inline">
                    <label class="layui-form-label">火化序号</label>
                    <div class="layui-input-inline">
                        <el-input v-model="crhData.CRHCDE"></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-inline">
                        <el-date-picker v-date v-model="staTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
                    </div>
                </div>
                <div class="layui-inline" v-if="isBEG">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-inline">
                        <el-date-picker v-date v-model="endTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">火化工</label>
                    <div class="layui-input-inline">
                        <el-select v-model="crhData.CRHOPRUSR" placeholder="请选择火化工" style="width:100%">
                            <el-option v-for="item in creUSES" :key="item.STAID" :label="item.STANAME" :value="item.STAID">
                            </el-option>
                        </el-select>
                    </div>
                </div>
            </div>
            </fieldset>
            <div class="layui-form-item btnCenter">
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" :loading="loading" @click="submit">提交</el-button>
            </div>
        </sweet-modal>
        <!-- 编辑 -->
        <sweet-modal v-if="hidden !== 1" ref="dialog" class="dialog">
            <h3>{{title}} </h3>
            <div style="margin:30px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">业务编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="crhData.REGNO" placeholder="请输入业务编号" @keyup.enter.native="getRegInfo" :disabled="isnum">
                            <el-button slot="append" icon="el-icon-search" @click="getRegInfo"></el-button>
                            </el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">火化工</label>
                        <div class="layui-input-inline">
                            <el-select v-model="crhData.CRHOPRUSR" placeholder="请选择火化工" style="width:100%" :disabled="this.title === '火化炉结束使用'">
                                <el-option v-for="item in fireStaff" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGNAME" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系人</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGHANDLERNAME" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGHANDLERLINK" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGREMARK" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline" v-if="showhuji">
                        <label class="layui-form-label">户籍地址</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGDETAILADDRESS" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline" v-if="showyou">
                        <label class="layui-form-label">使用油耗</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.CRHUSEOIL" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="this.isshow">
                    <div class="layui-inline">
                        <label class="layui-form-label">起始油量</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.CRHBEGOIL"></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">结束油量</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.CRHENDOIL"></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">炉子编号</label>
                        <div class="layui-input-inline">
                            <el-select v-model="crhData.CRENO" placeholder="请选择火化炉编号" style="width:100%" :disabled="readonlycreno">
                                <el-option v-for="item in creNames" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                        <div class="layui-inline" v-if="showluxing">
                        <label class="layui-form-label">火化炉类型</label>
                        <div class="layui-input-inline">
                             <el-select v-model="crhData.REGCRETYPE" filterable>
                                    <el-option v-for="item in hhldata" :key="item.Value" :label="item.Text" :value="item.Value">
                                    </el-option>
                                </el-select>
                         </div>
                         </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始时间</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date v-model="staTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
                        </div>
                    </div>
                    <div class="layui-inline" v-if="isBEG">
                        <label class="layui-form-label">结束时间</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date v-model="endTime" type="datetime" format="yyyy-MM-dd HH:mm" placeholder="选择时间"></el-date-picker>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" :loading="loading" @click="submit">提交</el-button>
            </div>
        </sweet-modal>
        <!-- 详情 -->
        <sweet-modal v-if="hidden === 1" ref="info" class="dialog" :sweetModalMaxWidth="930">
            <h3>{{title}} </h3>
            <fieldset class="layui-elem-field layui-field-title">
            <legend>死者信息</legend>
            <div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">业务编号</label>
                    <div class="layui-input-inline">
                        <el-input v-model="crhData.REGNO" placeholder="请输入业务编号" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">逝者姓名</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGNAME" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGSEXDESC" readonly></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">年龄</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGAGE" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">接尸日期</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGDATE" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">接尸地点</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGADDRESS" readonly></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">详细地址</label>
                    <div class="layui-input-inline" style="width:480px">
                        <el-input v-model="regList.REGDETAILADDRESS" readonly></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">联系人</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGHANDLERNAME" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">联系电话</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGHANDLERLINK" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.REGREMARK" readonly></el-input>
                    </div>
                </div>
            </div>
            </div>
            </fieldset>
            <fieldset class="layui-elem-field layui-field-title">
            <legend>火化炉使用信息</legend>
            <div class="layui-form-item" v-if="this.isshow">
                <div class="layui-inline">
                    <label class="layui-form-label">起始油量</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.CRHBEGOIL" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">结束油量</label>
                    <div class="layui-input-inline">
                        <el-input v-model="regList.CRHENDOIL" readonly></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-inline">
                        <el-select v-model="crhData.CRENOS" placeholder="请选择火化炉编号" style="width:100%">
                            <el-option v-for="item in creNames" :key="item.value" :label="item.label" :value="item.value" disabled>
                            </el-option>
                        </el-select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">火化序号</label>
                    <div class="layui-input-inline">
                        <el-input v-model="crhData.CRHCDE" readonly></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-inline">
                        <el-date-picker v-date v-model="staTime" type="datetime" placeholder="选择时间" readonly></el-date-picker>
                    </div>
                </div>
                <div class="layui-inline" v-if="isBEG">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-inline">
                        <el-date-picker v-date v-model="endTime" type="datetime" placeholder="选择时间" readonly></el-date-picker>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">火化工</label>
                    <div class="layui-input-inline">
                        <el-input v-model="crhData.CRHOPRUSR" readonly></el-input>
                    </div>
                </div>
            </div>
            </fieldset>
            <div class="layui-form-item btnCenter">
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" :loading="loading" @click="submit">提交</el-button>
            </div>
        </sweet-modal>
        <!-- 详情 -->
        <sweet-modal v-if="hidden !== 1" ref="info" class="dialog">
            <h3>{{title}} </h3>
            <div style="margin:30px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">业务编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="crhData.REGNO" placeholder="请输入业务编号" readonly></el-input>
                        </div>
                        <label class="layui-form-label">火化工</label>
                        <div class="layui-input-inline">
                            <el-select v-model="crhData.CRHOPRUSR" placeholder="请选择火化工" style="width:100%" disabled>
                                <el-option v-for="item in fireStaff" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGNAME" readonly></el-input>
                        </div>
                        <label class="layui-form-label">联系人</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGHANDLERNAME" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGHANDLERLINK" readonly></el-input>
                        </div>
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGREMARK" readonly></el-input>
                        </div>
                    </div>
                        <div class="layui-inline" v-if="showhuji">
                        <label class="layui-form-label">户籍地址</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.REGDETAILADDRESS" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline" v-if="showyou">
                        <label class="layui-form-label">使用油耗</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.CRHUSEOIL" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="isshow">
                    <div class="layui-inline">
                        <label class="layui-form-label">起始油量</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.CRHBEGOIL" readonly></el-input>
                        </div>
                        <label class="layui-form-label">结束油量</label>
                        <div class="layui-input-inline">
                            <el-input v-model="regList.CRHENDOIL" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">炉子编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="crhData.CRENOS" readonly></el-input>
                        </div>
                        <!-- <div class="layui-input-inline">
                            <el-select v-model="crhData.CRENOS" placeholder="请选择火化炉编号" style="width:100%">
                                <el-option v-for="item in creNames" :key="item.value" :label="item.label" :value="item.value" disabled>
                                </el-option>
                            </el-select>
                        </div> -->
                    </div>
                      <div class="layui-inline" v-if="showluxing">
                        <label class="layui-form-label">火化炉类型</label>
                        <div class="layui-input-inline">
                            <el-input v-model="REGCRETYPEDESC" readonly></el-input>
                         </div>
                         </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始时间</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date readonly v-model="staTime" format="yyyy-MM-dd HH:mm" type="datetime" placeholder="选择时间"></el-date-picker>
                        </div>
                        <label class="layui-form-label">结束时间</label>
                        <div class="layui-input-inline">
                            <el-date-picker v-date readonly v-model="endTime" format="yyyy-MM-dd HH:mm" type="datetime" placeholder="选择时间"></el-date-picker>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="infoClose">取消</el-button>
            </div>
        </sweet-modal>
    </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
<script>
    import sweetModal from "@/components/sweetModal";
    import apiBase from "@/api/apiBase.js";
    import {
        formatDate,
        timeStringToDate
    } from "@/utils/date.js";
    import {
        manage
    } from "@/mixins/managePage.js";
    const ADD = "新增";
    const MODIFY = "修改";
    const DELETE = "删除";
    const INFO = "详情";
    const BEG = "开始使用";
    const END = "结束使用";
    export default {
        name: "creUseMain",
        mixins: [manage],
        props: ['isUse'],
        data() {
            return {
                REGCRETYPEDESC:null,  //火化炉类型详情
                cre:null,
                hhldata: [],
                regList: {},
                creNames: [],
                crhData: {},
                staTime: null,
                endTime: null,
                isshow: null,
                hidden: null,
                creUSES: {},
                CRHID: null,
                readonlycreno: false,
                fireStaff: [],
                isywgetdata: null,
                isnum:true,
                showhuji:null,
                showyou:null,
                showluxing:null,
            }
        },
        methods: {
            open(order, id, cre) {
                this.order = order;
                this.getCrhs();
                this.readonlycreno = false;
                switch (this.order) {
                    case ADD:
                        this.isnum=false;
                        this.title = "火化炉使用新增"; //补录
                        this.dataRepeat();
                        this.$refs.dialog.open();
                        break;
                    case MODIFY:
                        this.title = "火化炉使用修改";
                        this.isnum=true;
                        this.cre=cre;
                        this.dataInfo(id);
                        this.readonlycreno = false;
                        this.$refs.dialog.open();
                        break;
                    case INFO:
                        this.title = "火化炉使用详情";
                        this.dataInfo(id);
                        this.$refs.info.open();
                        break;
                    case BEG:
                        this.title = "火化炉开始使用";//开始使用
                         this.isnum=false;
                        if(this.isUse === 1){
                            this.dataInfo(id);
                            this.CRHID = id
                        }else{
                            this.dataRepeat();
                            if(cre){
                                this.crhData.CRENO = id;
                                this.readonlycreno = true;
                            } 
                        }
                        // this.dataRepeat();
                        this.$refs.dialog.open();
                        break;
                    case END:
                        this.title = "火化炉结束使用";
                         this.isnum=true;
                        if(this.isywgetdata){
                            this.dataRepeat();//数据重置
                            // this.dataInfo(id);
                        }else{
                            this.dataInfo(id);//获取详情
                        }
                        
                        this.readonlycreno = false;
                        this.$refs.dialog.open();
                        break;
                    default:
                }
            },
            //提交
            submit() {
                switch (this.order) {
                    case ADD:
                        this.dataAdd();
                        break;
                    case MODIFY:
                        this.dataModify();
                        break;
                    case BEG:
                        this.startUse();
                        break;
                    case END:
                        this.endUse();
                        break;
                    default:
                }
            },
            //获取火化炉
            getCrhs() {
                apiBase.DoService({},
                    apiBase.getApiAdress().CremationUse.QueryCremation,
                    res => {
                        let creTypeData = res.data.content,
                            legendsCreData = creTypeData.map(item => ({
                                label: item.CRENO,
                                value: item.CREID
                            }));
                        this.creNames = legendsCreData;
                    }
                );
            },
            //根据正式业务编号获取ID
            getRegInfo() {
                if(this.isywgetdata && this.title == '火化炉结束使用'){
                    let data = {
                        CRHREGID: this.crhData.REGNO
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().CremationUse.DetailByCrhregid,
                        res => {
                            let reg = res.data.content;
                            if(!reg)
                            {
                                this.$message({
                                    type: "error",
                                    message: "未找到逝者信息!"
                                });
                                Object.assign(
                                    this.$data.regList,
                                    this.$options.data().regList
                                );
                                return;
                            }
                            this.regList = res.data.content;
                            this.crhData.CRENO = res.data.content.CRHCREID;
                            this.crhData.REGCRETYPE = res.data.content.REGCRETYPE;  // 上虞 获取炉子类型
                            this.crhData.CRHCREID = res.data.content.CRHCREID;  
                            this.crhData.CRHOPRUSR = res.data.content.CRHOPRUSR;   
                            this.staTime = timeStringToDate(
                                res.data.content.CRHBEGTIME,
                                res.data.content.CRHBEGDATE
                            );
                        }
                    );
                }else{
                    let data = {
                        REGNO: this.crhData.REGNO
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Registration.GetRegistrationByNo,
                        res => {
                            let reg = res.data.content;
                            if(!reg)
                            {
                            this.$message({
                            type: "error",
                            message: "未找到逝者信息!"
                            });
                            Object.assign(
                                this.$data.regList,
                                this.$options.data().regList
                                );
                            return;
                            }
                            this.regList = res.data.content;
                        }
                    );
                }
                
            },
            //新增
            dataAdd() {
                let Data = JSON.parse(JSON.stringify(this.crhData));
                apiBase.DoService({
                        CRHCREID: this.crhData.CRENO,
                        REGCRETYPE: this.crhData.REGCRETYPE,
                        CRHOPRUSR: this.crhData.CRHOPRUSR,
                        CRHREGID: this.regList.REGID,
                        CRHBEGOIL: this.regList.CRHBEGOIL,
                        CRHENDOIL: this.regList.CRHENDOIL,
                        CRHUSEOIL: this.regList.CRHUSEOIL,  //使用耗油量 （上虞）
                        CRHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
                        CRHBEGTIME: formatDate(this.staTime, "hhmmss"),
                        CRHENDDATE: formatDate(this.endTime, "yyyyMMdd"),
                        CRHENDTIME: formatDate(this.endTime, "hhmmss"),
                    },
                    apiBase.getApiAdress().CremationUse.Create,
                    res => {
                        this.$refs.dialog.close();
                        this.$message({
                            message: "新增成功！",
                            type: "success"
                        });
                        this.refreshData();
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    });
            },
            //详情
            dataInfo(id) {
                var data = {
                    CRHID: id
                };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().CremationUse.Detail,
                    res => {
                        this.crhData = res.data.content;
                        if(this.order === '详情'){
                            this.crhData.CRENOS = res.data.content.CRENO;
                        }else if(this.order === '修改' || this.order === '结束使用'){
                            this.crhData.CRENO = res.data.content.CRHCREID;
                        }
                        this.crhData.REGNO = this.crhData.REGBUSNUM;
                        this.crhData.CRHREGID=this.crhData.REGID; // 新加id
                        this.regList = this.crhData;
                        this.regList.REGREMARK = this.crhData.CRHREMARKS;
                        this.staTime = timeStringToDate(this.crhData.CRHBEGTIME, this.crhData.CRHBEGDATE);
                        this.endTime = timeStringToDate(this.crhData.CRHENDTIME, this.crhData.CRHENDDATE);
                        if(this.order === '开始使用'){
                            this.staTime = new Date()
                        }
                        if(this.order === '结束使用'){
                            this.endTime = new Date()
                        }
                        this.REGCRETYPEDESC=this.crhData.REGCRETYPEDESC
                    }
                );
            },
            //修改
            dataModify() {
                var data = {
                    CRHID: this.crhData.CRHID,
                    CRHCREID:this.crhData.CRENO,
                    REGCRETYPE:this.crhData.REGCRETYPE, // 修改炉类型
                    CRHREGID:this.crhData.CRHREGID, // 新加id
                    CRHOPRUSR: this.crhData.CRHOPRUSR,
                    CRHCDE: this.crhData.CRHCDE,
                    CRHBEGOIL: this.regList.CRHBEGOIL,
                    CRHENDOIL: this.regList.CRHENDOIL,
                    CRHUSEOIL: this.regList.CRHUSEOIL,   // 使用油耗 （上虞）
                    CRHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
                    CRHBEGTIME: formatDate(this.staTime, "hhmmss"),
                    CRHENDDATE: formatDate(this.endTime, "yyyyMMdd"),
                    CRHENDTIME: formatDate(this.endTime, "hhmmss")
                };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().CremationUse.Modify,
                    res => {
                        this.$refs.dialog.close();
                        this.$message({
                            message: "修改成功！",
                            type: "success"
                        });
                        this.refreshData();
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    });
            },
            //火化炉开始使用
            startUse() {
                if(this.isUse === 1){
                    apiBase.DoService({
                        CRHSTATUS: 'A',
                        CRHID: this.CRHID,
                        CRHCREID: this.crhData.CRENO,
                        CRHREGID: this.regList.REGID,
                        CRHOPRUSR: this.crhData.CRHOPRUSR,//火化工
                        REGCRETYPE: this.crhData.REGCRETYPE,//火化炉类型
                        CRHBEGOIL: this.regList.CRHBEGOIL,
                        CRHENDOIL: this.regList.CRHENDOIL,
                        CRHUSEOIL: this.regList.CRHUSEOIL,  // 使用耗油量
                        CRHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
                        CRHBEGTIME: formatDate(this.staTime, "hhmmss")
                    },
                    apiBase.getApiAdress().CremationUse.RegisterModify,
                    res => {
                        this.$refs.dialog.close();
                        this.$message({
                            type: "success",
                            message: "新增成功!"
                        });
                       this.refreshData();
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    });
                }else{
                    apiBase.DoService({
                        CRHCDE: this.crhData.CRHCDE,
                        CRHOPRUSR: this.crhData.CRHOPRUSR,//火化工
                        CRHCREID: this.crhData.CRENO,
                        REGCRETYPE: this.crhData.REGCRETYPE,//火化炉类型
                        CRHREGID: this.regList.REGID,
                        CRHBEGOIL: this.regList.CRHBEGOIL,
                        CRHENDOIL: this.regList.CRHENDOIL,
                        CRHBEGDATE: formatDate(this.staTime, "yyyyMMdd"),
                        CRHBEGTIME: formatDate(this.staTime, "hhmmss")
                    },
                    apiBase.getApiAdress().CremationUse.CremationStartUse,
                    res => {
                        this.$refs.dialog.close();
                        this.$message({
                            type: "success",
                            message: "新增成功!"
                        });
                       this.refreshData();
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    });
                }
            },
            //刷新
            refreshData() {
                this.$emit("refreshData");
            },
            //火化炉结束使用
            endUse() {
                apiBase.DoService({
                        CRHCREID: this.crhData.CRHCREID,
                        CRHREGID: this.regList.REGID,
                        CRHBEGOIL: this.regList.CRHBEGOIL,
                        CRHENDOIL: this.regList.CRHENDOIL,
                        CRHUSEOIL: this.regList.CRHUSEOIL,  //使用耗油 （上虞）
                        CRHENDDATE: formatDate(this.endTime, "yyyyMMdd"),
                        CRHENDTIME: formatDate(this.endTime, "hhmmss")
                    },
                    apiBase.getApiAdress().CremationUse.CremationEndUse,
                    res => {
                        this.$refs.dialog.close();
                        this.$message({
                            type: "success",
                            message: "结束使用成功!"
                        });
                        this.refreshData();
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    });
                    
            },
            //数据重置
            dataRepeat() {
                this.regList = {};
                this.creNames = null;
                this.crhData = {};
                this.staTime = null;
                this.endTime = null;
                this.regList.CRHBEGOIL = null;
                this.regList.CRHENDOIL = null;
            },
        },
        created(){
             var data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Param.GetCrhhasOil,
                    res => {
                        this.isshow = res.data.content;
                    });
                let Data = JSON.parse(JSON.stringify({stacodnameEqual: "火化工"}));
                apiBase.DoService(
                    {PageIndex: -1, PageSize: 10, OrderBy: null, OrderByType: null, Data: Data},
                    apiBase.getApiAdress().Staff.Query,
                    res => {
                        this.creUSES = res.data.content.OutData
                    });
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Param.GetCrePage,
                    res => {
                        this.hidden = res.data.content
                    });
                    // 是否显示户籍地址（上虞）
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Param.GetIsShowPermanentAddress,
                    res => {
                        this.showhuji = res.data.content
                    });
                   // 火化炉使用是否显示使用油耗（上虞）
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Param.GetIsShowOilConsumption,
                    res => {
                        this.showyou = res.data.content
                    });
                //控制结束使用是否自动获取数据
                apiBase.DoService(
                {},
                apiBase.getApiAdress().Param.GetIsControlUserQuery,
                res => {
                    this.isywgetdata = res.data.content;
                });
                //获取火化工
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Staff.QueryCremationstaff,
                    res => {
                        let copydata = res.data.content;
                        copydata.forEach(item => {
                            this.fireStaff.push({
                                value: item.CRHOPRUSR,
                                label: item.CRHOPRNAME
                            })
                        });
                    });
               // 火化炉使用是否显示火化炉类型（上虞）
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Param.GetIsShowCreUseCreType,
                    res => {
                        this.showluxing = res.data.content
                    });
                //获取预约火化炉类型
                apiBase.DoService(
                    data,
                    // apiBase.getApiAdress().Reserve.GetPrpCreationStatus,
                    apiBase.getApiAdress().Code.GetCremationType,
                    res => {
                        let creTypeData = res.data.content,
                            legendsCreData = creTypeData.map(item => ({
                                Text: item.CodeName,
                                Value: item.CodeValue
                            }));
                        this.hhldata = legendsCreData;
                        this.hhldata.unshift({ Text: "不选择", Value: "" });
                    }
                ); 
        },
        computed: {
            isBEG() {
                if (this.order == BEG) return false;
                if (this.order == MODIFY && this.cre == "A") return false;
                if (this.order == MODIFY && this.cre == "B") return false;
                else return true;
            },
            isEND() {
                if (this.order == END) return false;
                else return true;
            }
        },
        components: {
            sweetModal
        }
    };
</script>

